import sys
from PyQt5.QtWidgets import QApplication,QWidget,QMessageBox

class Example(QWidget):
    def __init__(self):
        super(Example, self).__init__()

    def initUI(self):

        self.setGeometry(300, 300, 500, 500)
        self.setWindowTitle("Message bos")
        self.show()

    def closeEvent(self, event):
        reply = QMessageBox.question(self, 'Massage', "Are you sure to quit?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No)

        if reply == QMessageBox.Yes:
            event.accept()
        else:
            event.ignore()
    def __call__(self):

        self.initUI()

if __name__ == '__main__':

    app = QApplication(sys.argv)
    ex = Example()
    ex.__call__()
    sys.exit(app.exec_())